//
//  PlasticMaterial.cpp
//  RayTracer
//
//  Created by 俞云康 on 3/26/16.
//  Copyright © 2016 yushroom. All rights reserved.
//

#include "PlasticMaterial.hpp"
#include "Params.hpp"
#include "Microfacet.hpp"
#include "Lambertian.hpp"

PlasticMaterial::PlasticMaterial(const Color& kd, const Color& ks, const float roughness)
: kd(kd), ks(ks), roughness(roughness) {
    
}

shared_ptr<Material> PlasticMaterial::create(const Params& params) {
    Color kd = params.getColor("kd");
    Color ks = params.getColor("ks");
    float roughness = params.getFloat("roughness");
    return make_shared<PlasticMaterial>(kd, ks, roughness);
}

shared_ptr<BSDF> PlasticMaterial::getBSDF(const HitInfo& hit)const {
    auto bsdf = std::make_shared<BSDF>(hit, hit.normal);
    auto fresnel = std::make_shared<FresnelDialectric>(1.5f, 1.f);
    auto blinn = make_shared<Blinn>(1.0f / roughness);
    //return make_shared<Microfacet>(&hit, ks, fresnel, blinn);
    bsdf->add(new Lambertian(&hit, kd));
    bsdf->add(new Microfacet(&hit, ks, fresnel, blinn));
    return bsdf;
}